<!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<title>通过计算属性直接绑定到组件对象上实现组件切换</title>
	<script src="vue.js"></script>
</head>
<body>
<div id="app">
  <button @click="change()">切换页面</button>
  <component :is="currentView"></component>
</div>
<script>
  var vm=new Vue({
      el: '#app',
      data:{
          index:0,
          arr:[
            {template:`<div>打开主页</div>`},
            {template:`<div>打开登录页面</div>`},
            {template:`<div>打开注册页面</div>`}
          ],
      },
      computed:{
          currentView(){
              return this.arr[this.index];
            }
          },
      methods:{
          change(){
			  let len = this.arr.length;
              this.index = (++this.index)% len;            
          }
        }
      })
</script>
</body>
</html>